package Thread;

class MyThread3 implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println("hello runnable");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class ThreadDemo3 {
    public static void main(String[] args) {
        // 两种写法

        // 1.
        Runnable runnable = new MyThread3();
        Thread thread = new Thread(runnable);
        thread.start();

        // 2.
        Thread thread1 = new Thread(new MyThread3());


        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
